package vulnerability

import (
	"fmt"

	v1 "github.com/anchore/grype-db/pkg/db/v1"
)

type MetadataStoreAdapter struct {
	store v1.VulnerabilityMetadataStoreReader
}

func NewMetadataStoreProvider(store v1.VulnerabilityMetadataStoreReader) *MetadataStoreAdapter {
	return &MetadataStoreAdapter{
		store: store,
	}
}

func (pr *MetadataStoreAdapter) GetMetadata(id, recordSource string) (*Metadata, error) {
	metadata, err := pr.store.GetVulnerabilityMetadata(id, recordSource)
	if err != nil {
		return nil, fmt.Errorf("metadata provider failed to fetch id='%s' recordsource='%s': %w", id, recordSource, err)
	}

	return NewMetadata(metadata)
}
